package com.joplus.housekeeper.ui.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.widget.ListView;

/**
 * Created by Administrator on 2016/11/3.
 */

public class StandVerticalListView extends ListView {

    Boolean isIntercep=false;//是否拦截了事件
    public StandVerticalListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public StandVerticalListView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {

        return super.dispatchTouchEvent(ev);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        float startX=0;
        float startY=0;

        Boolean intercept=true;
        if(isIntercep){
            isIntercep=false;
        }
        switch (ev.getAction()){
            case MotionEvent.ACTION_DOWN:
                startX=  ev.getRawX();
                startY=ev.getRawY();
                break;
            case MotionEvent.ACTION_MOVE:
                if(Math.abs(ev.getRawY()-startY)>Math.abs(ev.getRawX()-startX)){
                    intercept=  false;
                    isIntercep=true;
                }
                break;
            case MotionEvent.ACTION_UP:
                isIntercep=false;
                break;
        }
        if(intercept){
            return super.onInterceptTouchEvent(ev);
        }else{
           return false;
        }

    }
}
